<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Employer Profile</title>
<script type="text/javascript" src="../js/vcs_script.js"
	language="JavaScript"></script>
<script type="text/javascript">

	function validateUsername(fld){
		
		var error = "";
				
		if(fld.value == ""){
			error = "* You did not enter User Name \n";
			fld.style.background = 'Yellow';
		}else if(fld.value.length < 5 || fld.value.length > 15){
			error = "* User Name should be beteen 5 to 15 characters long\n";
			fld.style.background = 'Yellow';
		}else{
			fld.style.background = 'White';
		}
		return error;
	}

	function validatePassword(fld){
		var error = "";
		
		if(fld.value == ""){
			error = "* You did not enter Password\n";
			fld.style.background = 'Yellow';
		}else if(fld.value.length < 5 || fld.value.length > 15){
			error = "* Incorrect length of Password. Password should be between 5 to 15 characters long\n";
			fld.style.background = 'Yellow';
		}else{
			fld.style.background = 'White';
		}
		return error;
	}
	
	function trim(s)
	{
	  return s.replace(/^\s+|\s+$/, '');
	}

	function validateEmail(fld) {
	    var error="";
	    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
	    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	   
	    if (fld.value == "") {
	        fld.style.background = 'Yellow';
	        error = "* You didn't enter Email address.\n";
	    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
	        fld.style.background = 'Yellow';
	        error = "* Please enter a valid email address.(Eg. xyz@gmail.com)\n";
	    } else if (fld.value.match(illegalChars)) {
	        fld.style.background = 'Yellow';
	        error = "* The Email address contains illegal characters.\n";
	    } else {
	        fld.style.background = 'White';
	    }
	    return error;
	}
	
	function validateCompanyName(fld){
		var error = "";
		
		if(fld.value == ""){
			fld.style.background = 'Yellow';
			error = "* You did not enter Company Name\n";
		}else if(fld.value.length < 2){
			fld.style.background = 'Yellow';
			error = "* Company Name is too small\n";
		}else{
			fld.style.background = 'White';
		}
		return error;
	}
	
	function validateCompanyProfile(fld){
		var error = "";
		
		if(fld.value == ""){
			fld.style.background = 'Yellow';
			error = "* You didn't enter Company Profile\n";
		}else if(fld.value.length < 10){
			fld.style.background = 'Yellow';
			error = "* Company Profile is too small, Please make it more descriptive. It can be upto 300 characters long\n";
		}else{
			fld.style.background = 'White';
		}
		return error;
	}
	
	function validateContactPerson(fld){
		var error = "";
		
		if(fld.value == ""){
			fld.style.background = 'Yellow';
			error = "* You didn't enter Contact Person name\n";
		}else{
			fld.style.background = 'white';
		}
		return error;
	}
	function validateAddress(fld){
		
		var error = "";
		
		if(fld.value == ""){
			fld.style.background = 'Yellow';
			error = "* You didn't enter Address\n";
		}else if(fld.value.length < 10){
			fld.style.background = 'Yellow';
			error = "* Address is too small, Please enter detailed address with street name\n";
		}else{
			fld.style.background = 'White';
		}
		return error;
	}
		
	function validatePhone(fld) {
		
		var error = "";
		var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');

		if (fld.value == "") {
			error = "* You didn't enter a phone number.\n";
			fld.style.background = 'Yellow';
		} else if (isNaN(parseInt(stripped))) {
			error = "* The phone number contains illegal characters.\n";
			fld.style.background = 'Yellow';
		} else if (!(stripped.length == 10)) {
			error = "* The phone number is the wrong length. It should be 10 digit number(Without country code.)\n";
			fld.style.background = 'Yellow';
		}else{
			fld.style.background = 'White';
		}
		return error;
	}
	
	function validatePincode(fld){
		
		var error = "";
		var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');

		if (fld.value == "") {
			error = "* You didn't enter a Pin Code.\n";
			fld.style.background = 'Yellow';
		} else if (isNaN(parseInt(stripped))) {
			error = "* The Pin Code contains illegal characters.\n";
			fld.style.background = 'Yellow';
		} else if (!(stripped.length == 6)) {
			error = "* The Pin Code is of wrong length. It should be 6 digit number\n";
			fld.style.background = 'Yellow';
		}else{
			fld.style.background = 'White';
		}
		return error;
	}

	function validateFormOnSubmit(theForm) {
		var reason = "";
		
/*		
		reason += validateEmail(theForm.email);
		reason += validateCompanyName(theForm.companyName);
		reason += validateCompanyProfile(theForm.companyProfile);
		reason += validateContactPerson(theForm.contactPerson);
		reason += validateAddress(theForm.address);
		reason += validatePincode(theForm.pincode);
		reason += validatePhone(theForm.phone);
*/	
		if (reason != "") {
			alert("Some fields need correction:\n \n" + reason);
			return false;
		}
		
		return true;
	}
	
</script>
</head>
<body>
<s:fielderror></s:fielderror>
<h3><s:text name="editClientProfile.title">Content not available</s:text></h3>
<hr />
<s:text name="editClientProfile.msg">Content not available</s:text>
<br />
<br />
<s:if test="#session.client != null">
	<table border="0" cellpadding="2" cellspacing="2" align="left">
		<tr>
			<td><s:form action="update" method="post" namespace="/client"
				theme="css_xhtml" onsubmit="return validateFormOnSubmit(this)">
				<s:push value="#session.client">
					<s:hidden name="id"/>
					<s:hidden name="username" label="Username" labelposition="left" />
					<s:hidden name="password" label="Password" labelposition="left" />
					<s:hidden name="accountType"/>
					<s:hidden name="profileState"/>
					<s:hidden name="createdDate"/>
					<s:hidden name="updateDate"/>
					<s:hidden name="role"/>
					<s:textfield name="contactPerson" label="Contact Person"
						labelposition="left" maxlength="120" />
					<s:textfield name="designation" label="Designation"
						labelposition="left" maxlength="120"/>
					<s:textfield name="phone" label="Office Phone" labelposition="left" maxlength="15"/>
					<s:textfield name="mobile" label="Mobile Number"
						labelposition="left" maxlength="10" />
					<s:textfield name="email" label="Email" labelposition="left" maxlength="120"/>
					<s:textfield name="companyName" label="Company Name"
						labelposition="left" maxlength="120" />
					<s:textarea name="companyProfile" label="Company Profile"
						labelposition="left" rows="6" cols="30" />
					<s:select name="industryType" list="#application.industryList"
						listKey="id" listValue="name"
						label="Industry Type" labelposition="left" />
					<s:textarea name="address" label="Address" labelposition="left"
						rows="5" cols="30" />
					<s:select name="city" list='#application.locationList' listKey="id"
						listValue="name" label="Location" labelposition="left" />
					<s:textfield name="pincode" label="Pincode" labelposition="left" maxlength="6"/>
					<s:select name="country" list='#{"1":"India"}' label="Country"
						labelposition="left" />

					<s:submit name="submit" value="Update Details" align="center" />
				</s:push>
			</s:form></td>
		</tr>
	</table>
</s:if>
</body>
</html>